package com.example.springblog.service;

import com.example.springblog.mapper.BlogInfoMapper;
import com.example.springblog.mapper.UserInfoMapper;
import com.example.springblog.model.BlogInfo;
import com.example.springblog.model.UserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class UserService {

    @Autowired
    private UserInfoMapper userInfoMapper;
    private BlogInfoMapper blogInfoMapper;
    public UserInfo login(String userName) {
        return userInfoMapper.selectByName(userName);
    }

    public UserInfo selectUserInfoById(Integer userId) {
        return userInfoMapper.selectById(userId);
    }

    public UserInfo selectAuthorInfoById(Integer blogId) {
        BlogInfo blogInfo = blogInfoMapper.selectById(blogId);

        if(blogId == null && blogInfo == null){
            return null;
        }

        UserInfo userInfo = userInfoMapper.selectById(blogInfo.getUserId());
        return userInfo;
    }
}
